import { createStore } from 'vuex'

export default createStore({
  state: {
    list:JSON.parse(localStorage.getItem('list'))||[],
    name:localStorage.getItem('name')||'',//用来保存你的名字
  },
  getters: {
  },
  mutations: {
    add(state,obj){
        state.list.push(obj)
        console.log(state.list);
        localStorage.setItem('list',JSON.stringify(state.list))
    },
    del(state,index){
        state.list.splice(index,1)
        localStorage.setItem('list',JSON.stringify(state.list))
    },
    edit(state,obj){
        const {index,form} = obj
        state.list[index] = form
        localStorage.setItem('list',JSON.stringify(state.list))

    },
    setDefault(state,name){
        state.name = name
        localStorage.setItem('name',state.name)
    }
   
  },
  actions: {
  },
  modules: {
  }
})
